/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package util;

import core.Doctor;
import core.Visit;
import gui.PatientForm;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.Date;
import javax.swing.JMenuItem;
import javax.swing.JPopupMenu;
import util.JCalendar.CellType;

/**
 *
 * @author Marcin
 */
public class PopUpMenu extends JPopupMenu{
    JMenuItem itHoliday;
    JMenuItem itVisit;
    Doctor d;
    PopUpMenu(final Doctor d,final JCalendar cal) {
        itHoliday = new JMenuItem("Dodaj zwolnienie");
        itVisit = new JMenuItem("Pokaż pacjenta");
        this.d = d;
        if(cal.getCalendar().getSelectedRowCount() != 1 || cal.getCalendar().getSelectedColumnCount() != 1 || cal.calendarMap[cal.getCalendar().getSelectedRow()][cal.getCalendar().getSelectedColumn()] != CellType.VISIT)
        {
            itVisit.setEnabled(false);
        }
        itHoliday.addMouseListener(new MouseAdapter(){
            @Override
            public void mouseReleased(MouseEvent e) {
                cal.addEvent(JCalendar.CellType.HOLIDAY);
                int col[] = cal.getCalendar().getSelectedColumns();
                for(int c : col){
                    if(c!=0) {
                        d.addHoliday(cal.getSelectedDateStart(c),cal.getSelectedDateEnd(c));
                    }
                }
                cal.repaint();
            }
        });
        itVisit.addMouseListener(new MouseAdapter(){
            @Override
            public void mouseReleased(MouseEvent e) {
                int col[] = cal.getCalendar().getSelectedColumns();
                for(int c : col) {
                    new PatientForm(0,Visit.getPatientID(cal.getSelectedDateStart2(c),d),false).setVisible(true);
                }
                cal.repaint();
            }
        });
        add(itHoliday);
        add(itVisit);
    }
}
